<template>
    <div class="toast">{{message}}</div>
</template>

<script>
import { reactive, toRefs } from 'vue'
export default {
  name: 'Toast',
  props: ['message']
}
export const useToastEffect = () => {
  const toastData = reactive({
    show: false,
    toastMessage: ''
  })
  const showToast = (message) => {
    toastData.show = true
    toastData.toastMessage = message
    setTimeout(() => {
      toastData.show = false
      toastData.toastMessage = ''
    }, 1000)
  }
  const { show, toastMessage } = toRefs(toastData)
  return { showToast, show, toastMessage }
}
</script>

<style lang="scss" scoped>
.toast {
    position: fixed;
    left: 50%;
    top: 50%;
    // 垂直水平居中
    transform: translate(-50%, -50%);
    background: rgba(0, 0, 0, .35);
    padding: .1rem;
    border-radius: .05rem;
    color: #fff;
}
</style>
